extends StateBase

func enterState(ownerNode):
	pass
	
	
func exitState(ownerNode):
	pass
	
	
func process(delta, ownerNode):
	if Input.is_action_just_pressed("Attack"):
		stateMachine.changeState("StateUseWeapon", ownerNode)
		
	
func physicsProcess(delta, ownerNode):
	var player = ownerNode as PlayerScript
	if not ownerNode.is_on_floor():
		player.velocity.y += player.gravity * player.gravityScale * delta 

	if Input.is_action_just_pressed("ui_accept") and player.is_on_floor():
		player.velocity.y = player.JUMP_VELOCITY

	var inputDirection = Input.get_axis("ui_left", "ui_right")
	if inputDirection:
		player.velocity.x = move_toward(player.velocity.x, inputDirection * player.SPEED, player.acceleration * delta) 
	else:
		if not player.is_on_floor():
			player.velocity.x = move_toward(player.velocity.x, 0, player.airResist * delta)
		else:
			player.velocity.x = move_toward(player.velocity.x, 0, player.friction * delta)
	
	player.move_and_slide()
	updateAnimation(player, inputDirection)
	
	
func updateAnimation(player, inputDirection):
	if inputDirection:
		player.animations.flip_h = inputDirection < 0
		
	if player.is_on_floor():
		if not inputDirection:
			player.animations.play("Idle")
		else:
			player.animations.play("Run")
	else:
		if player.velocity.y < 0:
			player.animations.play("JumpUp")
		else:
			player.animations.play("JumpDown")


